package leetcode.code2207;

import leetcode.IDebug;

public class Solution implements IDebug {

	public long maximumSubsequenceCount(String text, String pattern) {
		char a = pattern.charAt(0), b = pattern.charAt(1);
		char[] cs = text.toCharArray();
		long cnta = 0, cntb = 0;
		long ans = 0;
		for (int i = 0; i < cs.length; i++) {
			char cur = cs[i];
			if (cur == a) {
				cnta++;
			} else if (cur == b) {
				ans += cnta;
				cntb++;
			}
		}
		return a != b ? ans + Math.max(cnta, cntb) : cnta * (cnta - 1) / 2 + cnta;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
